package com.ee.chat.api.controller;

import com.ee.chat.api.service.IWalletService;
import com.ee.chat.common.bean.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("wallet")
public class WalletController {
    private Logger log = LoggerFactory.getLogger(WalletController.class);

    @Resource
    IWalletService walletService;

    /**
     * 我的钱包
     * @Author Shane
     * @Date 2019/8/2211:38
     * @param
     * @return
     **/
    @RequestMapping("getMyWallet")
    public Result getMyWealth(@RequestParam String token){
        try {
            return walletService.getMyWallect(token);
        }catch (Exception e){
            log.error("【获取个人钱包错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取充值套餐列表
     * @Author Shane
     * @Date 2019/8/2211:40
     * @param type  类型，0-微信支付宝  1-苹果内购
     * @return
     **/
    @RequestMapping("getRechargePackages")
    public Result getRechargePackages(@RequestParam String token, @RequestParam(required = false, defaultValue = "0") Integer type){
        try {
            return walletService.getRechargePackages(token, type);
        }catch (Exception e){
            log.error("【获取充值套餐列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 确认充值
     * @Author Shane
     * @Date 2019/8/2211:55
     * @param payWay  充值类型，0-微信  1-支付宝  2-苹果内购
     * @param packageId 充值套餐id
     * @return
     **/
    @RequestMapping("affirmRecharge")
    public Result affirmRecharge(@RequestParam String token, @RequestParam Integer payWay, @RequestParam Integer packageId){
        try {
            return walletService.affirmRecharge(token, payWay, packageId);
        }catch (Exception e){
            log.error("【确认充值错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取充值记录
     * @Author Shane
     * @Date 2019/8/2216:48
     * @param
     * @return
     **/
    @RequestMapping("getRechargeLog")
    public Result getRechargeLog(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer limit){
        try {
            return walletService.getRechargeLog(token, page, limit);
        }catch (Exception e){
            log.error("【获取充值记录】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取消费记录
     * @Author Shane
     * @Date 2019/8/2217:48
     * @param
     * @return
     **/
    @RequestMapping("getConsumeLog")
    public Result getConsumeLog(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer limit){
        try {
            return walletService.getConsumeLog(token, page, limit);
        }catch (Exception e){
            log.error("【获取消费记录】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取金币兑换套餐列表
     * @Author Shane
     * @Date 2019/9/317:26
     * @param
     * @return
     **/
    @RequestMapping("getExchangePackages")
    public Result getExchangePackages(@RequestParam String token){
        try {
            return walletService.getExchangePackages(token);
        }catch (Exception e){
            log.error("【获取兑换套餐列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取提现套餐列表
     * @Author Shane
     * @Date 2019/9/318:02
     * @param 
     * @return
     **/
    @RequestMapping("getWithdrawPackages")
    public Result getWithdrawPackages(@RequestParam String token){
        try {
            return walletService.getWithdrawPackages(token);
        }catch (Exception e){
            log.error("【获取提现套餐列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 积分兑换
     * @Author Shane
     * @Date 2019/9/414:52
     * @param packageId 套餐id
     * @return
     **/
    @RequestMapping("exchangePackage")
    public Result exchangePackage(@RequestParam String token, @RequestParam Integer packageId){
        try {
            return walletService.exchangePackage(token, packageId);
        }catch (Exception e){
            log.error("【积分兑换金币错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取积分兑换记录
     * @Author Shane
     * @Date 2019/10/6 18:55
     * @param
     * @return
     */
    @RequestMapping("getExchangeLog")
    public Result getExchangeLog(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer limit){
        try {
            return walletService.getExchangeLog(token, page, limit);
        }catch (Exception e){
            log.error("【获取积分兑换记录错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 积分提现
     * @Author Shane
     * @Date 2019/9/414:54
     * @param packageId 套餐id
     * @param way   途径，0-微信  1-支付宝
     * @return
     **/
    @RequestMapping("withdrawPackage")
    public Result withdrawPackage(@RequestParam String token, @RequestParam Integer packageId, @RequestParam Integer way){
        try {
            return walletService.withdrawPackage(token, packageId, way);
        }catch (Exception e){
            log.error("【积分提现错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 积分提现记录
     * @Author Shane
     * @Date 2019/10/25 0:33
     * @param
     * @return
     */
    @RequestMapping("getWithdrawLog")
    public Result getWithdrawLog(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer limit){
        try {
            return walletService.getWithdrawLog(token, page, limit);
        }catch (Exception e){
            log.error("【获取积分提现记录错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 绑定支付途径
     * @Author Shane
     * @Date 2019/9/417:59
     * @param way   支付方式,0-微信  1-支付宝
     * @param payNo 支付账号
     * @param payName   支付实名
     * @return
     **/
    @RequestMapping("bindPayWay")
    public Result bindPayWay(@RequestParam String token, @RequestParam Integer way, @RequestParam String payNo, @RequestParam String payName){
        try {
            return walletService.bindPayWay(token, way, payNo, payName);
        }catch (Exception e){
            log.error("【绑定支付错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取积分明细
     * @Author Shane
     * @Date 2019/11/7 11:07
     * @param
     * @return
     **/
    @RequestMapping("getCreditLog")
    public Result getCreditLog(@RequestParam String token, @RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer limit){
        try {
            return walletService.getCreditLog(token, page, limit);
        }catch (Exception e){
            log.error("【获取积分明细错误】", e);
        }
        return Result.returnFailure();
    }
}
